﻿using FurnitureDesign.Core.Models;
using FurnitureDesign.Core.Repository;
using FurnitureDesign.Mvc.Controllers;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace FurnitureDesign.Mvc.Areas.Admin.Controllers
{
    [Area("Admin")]
    public class LoginController : BaseController
    {
        private readonly ILogger<HomeController> _logger;
        private readonly IRepository<User, int> _repository;
        

        public LoginController(ILogger<HomeController> logger, IRepository<User, int> repository)
        {
            _logger = logger;
            _repository = repository;
        }
        public IActionResult Index()
        {
            return View();
        }
        public async Task<IActionResult> Login(string Name, string Password)
        {
            User user = await _repository.FirstOrDefaultAsync(s => s.Name == Name);
            if (user == null)
            {
                return Json(new { Success = false, Message = "用户名不存在" });
            }
            else
            {
                if (user.Password == Password)
                {
                    //FormsAuthentication.SetAuthCookie(Name, false);//颁发通行证 

                    //未填写
                    return Json(AjaxResult(true));
                }
                {
                    return Json(AjaxResult(false));
                }
            }
        }
        public ActionResult LoginOut()
        {
            //FormsAuthentication.SignOut(); //注销通行证
            return Redirect("/Admin/Login/Index");
        }
    }
}
